package com.mvvm.ktnet.ui.dao

import android.os.Bundle
import android.util.Log
import com.android.ktx.view.onClick
import com.mvvm.ktnet.R
import com.mvvm.ktnet.base.myappbase.BaseDbActivity
import com.mvvm.ktnet.base.viewmodel.BaseViewModel
import com.mvvm.ktnet.daoUtil.GreenDaoStudentUtils
import com.mvvm.ktnet.daoUtil.GreenDaoUtils
import com.mvvm.ktnet.daoUtil.TestDaoManager
import com.mvvm.ktnet.databinding.AcTestDaoBinding
import com.mvvm.ktnet.entity.TestDao

class TestDaoActivity : BaseDbActivity<BaseViewModel, AcTestDaoBinding>() {
    override fun layoutId(): Int = R.layout.ac_test_dao

    override fun initView(savedInstanceState: Bundle?) {

        GreenDaoUtils.getInstance().toInit()
        mDatabind.add.onClick {

            TestDaoManager.insert(TestDao().apply {
                test1 = "ssss"
                test2 = 100
                userId = "userId"
            })
        }
        val list = GreenDaoStudentUtils.getInstance().getStudentDao().queryBuilder().list()

        list.forEach {

            Log.e("输出", "student: id${it.id} ${it.name} ${it.age}" )

        }


    }

    override fun createObserver() {

    }

    override fun onDestroy() {
        super.onDestroy()
        GreenDaoUtils.getInstance().getBaseDb().close()
    }

    override fun initData() {

    }
}